package org.apache.lucene.store;

public class ByteArrayIndexInput extends IndexInput {
  private int position = 0;
  private byte[] bytes;
  
  public ByteArrayIndexInput(byte[] bytes) {
    this.bytes = bytes;
  }
  
  public long length() {
    return bytes.length;
  }

  public void readBytes(byte[] b, int offset, int len) {
    if (bytes == null) {
      throw new NullPointerException();
    } else if (offset < 0 || len < 0 || len > b.length - offset) {
      throw new IndexOutOfBoundsException();
    }
    //if (position >= bytes.length) {
    //  return -1;
    //}
    if (position + len > b.length) {
      len = bytes.length - position;
    }
    //if (len <= 0) {
    //  return 0;
    //}
    System.arraycopy(bytes, position, b, offset, len);
    //position += len;
    //return len;
  }

  public byte readByte() {
    byte b = bytes[position];
    position++;
    return b;
  }

  public long getFilePointer() {
    return position;
  }

  public void seek(long position) {
    this.position = (int) position;
  }

  public void close() {
  }
}
